package com.example.demo.verify;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

public class NoMoneyValidator implements ConstraintValidator<NoMoney, Object> {
    @Override
    public boolean isValid(Object obj, ConstraintValidatorContext context) {
        if (obj == null || obj.toString().trim().isEmpty()) {
            return false;
        }

        String reg = "^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$"; //判断小数点后2位的数字的正则表达式
        return Pattern.matches(reg, obj.toString());
    }
}
